/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

/**
 * <p>Project: javaseapp - Ex01
 * <p>Powered by webrx On 2021-08-11 16:18:32
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 16
 */
public class Ex01 {
    static int num = 0;
    static int coderow = 0;

    public static void main(String[] args) throws IOException {
        String p = "D:/ftp/javase/javaseapp/09part";
        count(new File(p));
        System.out.println(num);
        System.out.println(coderow);
    }

    public static void count(File file) throws IOException {
        if (file.isDirectory()) {
            for (File f : file.listFiles()) {
                if (f.isDirectory()) {
                    count(f);
                } else if (f.isFile()) {
                    String name = f.getName();
                    if (name.endsWith(".java")) {
                        //System.out.println(f.getAbsolutePath());
                        //System.out.println(f.getName());
                        ++num;

                        //统计当前文件的行数
                        FileInputStream fis = new FileInputStream(f);
                        String code = new String(fis.readAllBytes());
                        long rows = code.lines().count();
                        coderow += rows;
                        System.out.printf("%s(%d)%n", f.getAbsolutePath(), rows);
                    }
                }
            }
        }
    }
}
//a
